package com.study.jsl;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONReader;
import com.alibaba.fastjson2.TypeReference;
import com.study.demo.JsonRootBean;
import com.study.demo.QsBean;
import com.study.utils.SysUtils;
import org.junit.jupiter.api.Test;

import java.time.LocalDate;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author zhuzi
 * 2023/9/9 20:35
 * 集思录强赎
 */
public class QsDemo {

    @Test
    public void test1() {
        String file = "config/qs.json";
        String s = SysUtils.loadFile(file);

        //RootBeanDTO<Cell> rootBeanDTO = JSON.parseObject(body, new TypeReference<RootBeanDTO<Cell>>() {
        //}, JSONReader.Feature.SupportSmartMatch);
        JsonRootBean<QsBean> jsonRootBean = JSON.parseObject(s, new TypeReference<JsonRootBean<QsBean>>() {
        }, JSONReader.Feature.SupportSmartMatch);

        List<JsonRootBean.Rows<QsBean>> rows = jsonRootBean.getRows();


        List<QsBean> qsBeans = rows.stream().map(item -> item.getCell()).collect(Collectors.toList());

        Map<String, List<QsBean>> mapType = qsBeans.stream().collect(Collectors.groupingBy(QsBean::getBtype));

        // E 是
        Set<String> strings = mapType.keySet();
        //System.out.println(strings);

        List<QsBean> stStock = qsBeans.stream().filter(item -> item.getStockNm().contains("ST")).collect(Collectors.toList());
        System.out.println(stStock.size());


        //https://img-blog.csdnimg.cn/38094e0838b74f80a2c56bba4dd022f7.png#pic_center
        // Y 强赎 N 不强赎 X 天数
        Map<String, List<QsBean>> mapRedeem = qsBeans.stream().collect(Collectors.groupingBy(QsBean::getRedeemFlag));


        List<QsBean> filter = filter(qsBeans);
        filter.forEach(item -> item.calc());

        System.out.println("-------------");

        filter.sort(Comparator.comparing(QsBean::getSd));
        filter.forEach(System.out::println);

    }

    /**
     * 过滤
     * <p>
     * 排除沪市转债，强赎天数小于5，公告强赎债，ST债
     * </p>
     *
     * @param list 集合
     */
    public static List<QsBean> filter(List<QsBean> list) {
        return list.stream().filter(item -> item.filter()).collect(Collectors.toList());
    }

    @Test
    public void test() {
        LocalDate localDate = LocalDate.parse("2019-10-16");
        LocalDate endDate = localDate.plusYears(5).plusMonths(6);
        System.out.println(endDate);

        System.out.println(LocalDate.now().isBefore(endDate));

    }
}
